home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PAS_0793 / SHARING.TXT < prev    next >
Text File  |  1993-08-01  |  4KB  |  91 lines

  1. ─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 61 of 62                                                                 
  3. From : Daniel Stark                        1:243/31.0           30 Jun 93  00:38 
  4. To   : Mike Kogge                          1:260/410.0                           
  5. Subj : Locking                                                                
  6. ────────────────────────────────────────────────────────────────────────────────
  7. Hello Mike!
  8.  
  9. Sunday June 27 1993 17:28, Mike Kogge wrote to All:
  10.  
  11.  MK> @REG: TE-1.b/UR
  12.  MK> I am currently writing a BBS in BP 7.0. The problem is, I have no idea on
  13.  MK> how to and what files to lock.
  14.  
  15.  MK> I have TPSHAR200.ZIP, but that didn't help much in explaining the
  16.  MK> deny/read only, etc. commands. What would I have to lock? What type of
  17.  MK> files? When do I unlock them?
  18.  
  19.  MK>   1.. Would I lock display files to read only?
  20.  MK>   2.. Locking the message base to read only, unlock when a user writes,
  21.  MK> the relock? 3. Lock the file lists to read only? 4. Lock the users file to
  22.  MK> read only, yet when nessecary unlock it and then write to it, then relcok
  23.  MK> 5. Do I need to lock the files avail to dload?
  24.  
  25.  MK> Please help me here. Also, must I lock at a certain point in the file? I
  26.  MK> know STANDARD PASCAL, and taught myself OOP, but some of this stuff is new
  27.  MK> to me.
  28.  
  29.  MK> Thanks alot. I appreciate ANY help given.
  30.  
  31.  
  32. File sharing
  33. ------------
  34.  
  35. (Shortly explained by jonny bergdahl, 2:204/503)
  36.  
  37. When sharing files concurrently, by means of for example a multitasker or a
  38. network, it is necessary to use the file sharing as provided by the DOS command
  39. SHARE, or as provided by a Network shell (In Novell file sharing is supported
  40. by
  41. the network shell on Servers, not locally. Check your network documentation for
  42. more information).
  43.  
  44. File sharing is simple in TP/BP, since the system variable FileMode defines in
  45. what mode a certain file is opened in:
  46.  
  47. Const
  48.    fmReadOnly  = $00;  (* *)
  49.    fmWriteOnly = $01;  (* Only one of these should be used *)
  50.    fmReadWrite = $02;  (* *)
  51.  
  52.    fmDenyAll   = $10;  (* together with only one of these  *)
  53.    fmDenyWrite = $20;  (* *)
  54.    fmDenyRead  = $30;  (* *)
  55.    fmDenyNone  = $40;  (* *)
  56.  
  57.    fmNoInherit = $70;  (* Set for "No inheritance"         *)
  58.  
  59.  
  60. Construction the FileMode variable is easy, just add the appropriate values:
  61.  
  62. FileMode:=fmReadOnly+fmDenyNone;
  63.       (Open file for reading only, allow read and write.)
  64.  
  65. FileMode:=fmReadWrite+fmDenyWrite;
  66.       (Open file for both read and write, deny write.)
  67.  
  68. FileMode:=fmReadWrite+fmDenyAll;
  69.       (Open file for both read and write, deny all.)
  70.  
  71. Say you open the file in "fmReadWrite+fmDenyWrite". This will let you read and
  72. write freely in the file, while other processes can freely read the file. If
  73. another process tries to open the file for writing, that process will get the
  74. error "Access denied".
  75.  
  76. (fmNoInherit is seldom used - it defines if a childprocess spawn from your
  77. process will be able to use the filehandle provided by your process.)
  78.  
  79. The FileMode variable is only used when the file is opened;
  80.  
  81.  ...
  82. Assign(F,FileName);
  83. FileMode:=fmReadOnly+fmDenyNone;
  84. Reset(F);
  85. FileMode:=<Whatever>    (* Changing FileMode here does not affect the
  86.                            files already opened *)
  87.  
  88. By default, FileMode is defined as FileMode:=$02 in TP/BP, this is referred to
  89. as "compatibility mode" in the TP/BP docs. Two processes accessing the same
  90. file
  91. with this filemode results in the critical error "Sharing violation".